﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

//using llano.service;
using CF.Data;
using CF.Service;

namespace CF.Web
{
    public partial class InitData : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            InsertData();
            //ChangeData();
        }

        //BaseService<TColumn, TColumn, string> bs = new BaseService<TColumn, TColumn, string>();

        private void ChangeData()
        {
            //List<TColumn> list = bs.EntityDAO.Load("s.TableName = 'adClass' and s.ProjectName = 'sp'", new Dictionary<string, object>());
            //foreach (TColumn c in list)
            //{
            //    c.ProjectName = "ZP";
            //    bs.EntityDAO.Save(c);
            //}
            //Response.Write(list.Count);
        }

        private void InsertData()
        {
            //string data = FileHelper.ReadFile("InitData.htm");
            //string[] dataArr = data.Split(';');
            //foreach (string single in dataArr)
            //{
            //    if (string.IsNullOrWhiteSpace(single)) continue;
            //    string[] table = single.Split(char.Parse(","));
            //    if (table[1].ToLower() == "id") continue;
            //    string[] pj = table[0].Split('_');
            //    if (HaveColumn(table[1], pj[1], pj[0])) continue;
            //    TColumn c = new TColumn();
            //    c.ProjectName = pj[0]; c.TableName = pj[1]; c.NameEN = table[1]; 
            //    c.Type = table[1].ToLower().Contains("id") ? "int" : table[2];
            //    c.Field = "TextField"; c.IsQuery = true;
            //    bs.EntityDAO.Save(c);
            //}
        }

        private bool HaveColumn(string NameEN, string TableName, string ProjectName)
        {
            //Dictionary<string, object> dc = new Dictionary<string, object>();
            //dc.Add("NameEN", NameEN); dc.Add("TableName", TableName); dc.Add("ProjectName", ProjectName);
            //return bs.EntityDAO.Load("s.NameEN = :NameEN and s.TableName = :TableName and s.ProjectName = :ProjectName ", dc).Count > 0;
            return false;
        }
    }
}